@echo off
setlocal enabledelayedexpansion

set ROOT_DIR=%~dp0..

set REPO_DIR=%ROOT_DIR%\repositories\com.anlogic.sdk.repository\target\repository

cd /d %ROOT_DIR%

@REM modify about.mappings file to update ide version
set aboutFile=%ROOT_DIR%\plugins\com.anlogic.sdk.product\about.mappings
set aboutFileTmp=%ROOT_DIR%\about.mappings.tmp

set updateVersion=1

if "%updateVersion%" == 1 (
    if exist "%aboutFileTmp%" del "%aboutFileTmp%"
    for /f "tokens=1* delims=:" %%i in ('findstr /n "^" "%aboutFile%"') do (
        set "line=%%j"
        @REM echo !line!
        if "!line!"=="" (
            echo.>> %aboutFileTmp%
        ) else if "!line:~0,2!"=="0=" (
            set curLine=0=%date:~0,4%%date:~5,2%%date:~8,2%
            echo !curLine!>> %aboutFileTmp%
        ) else if "!line:~0,2!"=="1=" (
            set curLine=1=%date:~0,4%.%date:~5,2%
            echo !curLine!>> %aboutFileTmp%
        ) else (
            echo !line!>> %aboutFileTmp%
        )
    )
    move /y "%aboutFileTmp%" "%aboutFile%"
) 

@REM build the project
@REM call mvn clean verify


@REM copy plugins to the FD directory
set FD_DIR=E:\AnlogicSDK\Software\FutureDynasty
set ECLIPSE_DIR=eclipse-cpp-2025.03

del %FD_DIR%\%ECLIPSE_DIR%\plugins\com.anlogic.sdk*
del %FD_DIR%\%ECLIPSE_DIR%\plugins\org.eclipse.embedcdt.debug.gdbjtag.openocd.*
del %FD_DIR%\%ECLIPSE_DIR%\plugins\org.eclipse.embedcdt.managedbuild.cross.arm.*
del %FD_DIR%\%ECLIPSE_DIR%\plugins\org.eclipse.embedcdt.managedbuild.cross.riscv.*
del %FD_DIR%\%ECLIPSE_DIR%\plugins\org.eclipse.embedcdt.managedbuild.cross.ui.*
del %FD_DIR%\%ECLIPSE_DIR%\plugins\org.eclipse.embedcdt.ui.*

del %FD_DIR%\%ECLIPSE_DIR%\plugins\com.googlecode.cppcheclipse.*

copy %REPO_DIR%\plugins\* %FD_DIR%\%ECLIPSE_DIR%\plugins\
